<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2023/12/18
  Time: 22:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.example.ending_demo.model.Address" %>
<%@ page import="com.example.ending_demo.model.PageInfo" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link type="text/css" href="css/bootstrap.min.css" rel="stylesheet"/>
    <link type="text/css" href="css/mystyles.css" rel="stylesheet"/>
    <title>搜索结果</title>
</head>
<body>
<%@ include file="header.jsp"%>


<div class="width-80">
    <h3>搜索结果</h3>
    <div class="min-height">
        <table class="table table-hover">
            <thead>
            <tr>
                <th>#</th>
                <th>姓名</th>
                <th>手机号码</th>
                <th>邮箱地址</th>
                <th>通讯地址</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach var="addr" items="${requestScope.searchPage.items}">
                <tr>
                    <th scope="row">${addr.address_id}</th>
                    <td>${addr.addr_username}</td>
                    <td>${addr.addr_phone}</td>
                    <td>${addr.addr_email}</td>
                    <td>${addr.address}</td>
                    <td>
                        <a type="button" href="AddressEditServlet?id=${addr.address_id}"  class="btn btn-info">编辑</a>
                        <a type="button" href="AddressDeleteServlet?id=${addr.address_id}" class="btn btn-danger" >删除</a>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
</div>

<%--  分页条的开始  --%>
<div class="text-center">
    <ul class="pagination">
        <li>
            <a href="${requestScope.searchPage.url}&pageNo=${requestScope.searchPage.pageNo-1}" aria-label="Previous">
                <span aria-hidden="true">&laquo;</span>
            </a>
        </li>
        <%--页码输出的开始--%>
        <c:choose>
            <%--   情况一：如果总页码小于等于5的情况，页码的范围是：1-总页码  --%>
            <c:when test="${requestScope.searchPage.pageTotal<=5}">
                <%-- <c:set var ="" value="" ></c:set> 是给属性设置值        --%>
                <c:set var="begin" value="1"></c:set>
                <c:set var="end" value="${requestScope.searchPage.pageTotal}"></c:set>
            </c:when>
            <%--情况2：总页码大于5的情况--%>
            <c:when test="${requestScope.searchPage.pageTotal>5}">
                <c:choose>
                    <%--小情况1：当前页码为前面3个：1，2，3的情况，页码范围是：1-5   --%>
                    <c:when test="${requestScope.searchPage.pageNo <= 3}">
                        <c:set var="begin" value="1"/>
                        <c:set var="end" value="5"/>
                    </c:when>
                    <%--小情况2：当前页码为最后3个，8，9，10，页码范围是：总页码减4 - 总页码 --%>
                    <c:when test="${requestScope.searchPage.pageNo > requestScope.searchPage.pageTotal-3}">
                        <c:set var="begin" value="${requestScope.searchPage.pageTotal-4}"/>
                        <c:set var="end" value="${requestScope.searchPage.pageTotal}"/>
                    </c:when>
                    <%--小情况3：4，5，6，7，页码范围是：当前页码减2 - 当前页码加2  --%>
                    <c:otherwise>
                        <c:set var="begin" value="${requestScope.searchPage.pageNo-2}"/>
                        <c:set var="end" value="${requestScope.searchPage.pageNo+2}"/>
                    </c:otherwise>
                </c:choose>
            </c:when>
        </c:choose>


        <c:forEach begin="${begin}" end="${end}" var="i">
            <c:if test="${i==requestScope.searchPage.pageNo}">
                <li class="disabled"><a href="#">${i}</a></li>
            </c:if>
            <c:if test="${i != requestScope.searchPage.pageNo}">
                <li><a href="${requestScope.searchPage.url}&pageNo=${i}">${i}</a></li>
                <a href="${requestScope.searchPage.url}&pageNo=${i}">${i}</a>
            </c:if>
        </c:forEach>


        <li>
            <a href="${requestScope.searchPage.url}&pageNo=${requestScope.searchPage.pageNo+1}" aria-label="Next">
                <span aria-hidden="true">&raquo;</span>
            </a>
        </li>
    </ul>

</div>
<%@ include file="footer.jsp"%>
<script type="text/javascript" src="js/jquery-3.6.1.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</body>
</html>

